From ff7056702895bb2802b709e8143a799a65d31c87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 12 Mar 2007 01:40:39 +0000 Subject: [PATCH] go fishing for an existing fish for the source/destination combination * babl/babl-fish.c: (fishing_result_examine), (go_fishing), (babl_fish): go fishing for an existing fish for the source/destination combination before trying to create one. svn path=/trunk/; revision=226 --- ChangeLog | 6 +++++ babl/babl-fish.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9942394..408fd8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-03-12 Øyvind Kolås + + * babl/babl-fish.c: (fishing_result_examine), (go_fishing), + (babl_fish): go fishing for an existing fish for the + source/destination combination before trying to create one. + 2007-02-22 Øyvind Kolås * babl/babl-classes.h: make _Babl be a typedef and not a union that diff --git a/babl/babl-fish.c b/babl/babl-fish.c index cb5a302..c01de2a 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -56,6 +56,58 @@ babl_fish_db (void) return db; } +typedef struct BablFishingData +{ + Babl *source; + Babl *destination; + Babl *ret; +} BablFishingData; + +static int +fishing_result_examine (Babl *babl, + void *void_data) +{ + BablFishingData *data = void_data; + + if ((void*)data->source == (void*)babl->fish.source && + (void*)data->destination == (void*)babl->fish.destination) + { + data->ret = babl; + return 1; /* stop iterating */ + } + return 0; /* continue iterating */ +} + +static int yes=0; +static int no=0; + +static Babl * +go_fishing (Babl *source, + Babl *destination) +{ + { + BablFishingData data; + + data.source = source; + data.destination = destination; + data.ret = NULL; + + + babl_db_each (db, fishing_result_examine, &data); + + if (data.ret != NULL) + { + yes++; + } + else + { + no++; + } + + return data.ret; + } +} + Babl * babl_fish (void *source, void *destination, @@ -98,7 +150,13 @@ babl_fish (void *source, babl_log ("args=(%p, %p) destination format invalid", source, destination); return NULL; } - + + { + Babl *lucky; + lucky = go_fishing (source_format, destination_format); + if (lucky) + return lucky; + } if (0) { @@ -113,7 +171,6 @@ babl_fish (void *source, } } - { Babl *fish_path; -- 2.30.2